package org.nerve.okhttp3.facebook;

/**
 * org.nerve.okhttp3.facebook
 * Created by zengxm on 2016/7/28.
 */
public class ProfileUrl {
	/*
	URL中有5出动态参数
	1   目标id，profile_id
	2   最新日期，end
	3   分页，page_index
	4   offset（分页用的，开始值是0），tipld.sc
	5  当前登录的用户ID，__user
	 */
	protected static String URL="https://www.facebook.com/ajax/pagelet/generic.php/ProfileTimelineSectionPagelet?dpr=1&ajaxpipe=1&ajaxpipe_token=AXhF-GRi6h9cQvmK&no_script_path=1&data={\"profile_id\":%s,\"start\":0,\"end\":%d,\"query_type\":8,\"filter_after_timestamp\":0,\"buffer\":500,\"current_scrubber_key\":\"year_2016\",\"page_index\":%d,\"require_click\":false,\"section_container_id\":\"u_jsonp_67_1\",\"section_pagelet_id\":\"pagelet_timeline_year_current\",\"unit_container_id\":\"u_jsonp_67_0\",\"showing_esc\":false,\"adjust_buffer\":false,\"tipld\":{\"sc\":%d,\"vc\":5},\"num_visible_units\":5,\"remove_dupes\":true}&__user=%s&__a=1&__req=&__be=-1&__pc=PHASED:DEFAULT&__adt=1";
	public static final int DEFAULT_PAGE_SIZE=8;        //facebook默认一个请求返回8条数据

	protected String targetId;
	protected String userId;

	protected long end= System.currentTimeMillis()/1000;
	protected int pageIndex=0;
	protected int current=0;        //当前已经加载了多少条数据

	public String getTargetId() {
		return targetId;
	}

	public String getUserId() {
		return userId;
	}

	public long getEnd() {
		return end;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public int getCurrent() {
		return current;
	}

	public ProfileUrl(String tid, String uid){
		targetId=tid;
		userId=uid;
	}

	/**
	 * 挪动指针
	 * @param c
	 */
	public ProfileUrl add(int c){
		current+=c;

		return this;
	}

	/**
	 * 获得url地址
	 * @return
	 */
	public String get(){
		pageIndex++;
		return String.format(URL, targetId, end, pageIndex, current, userId);
	}
}
